﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FriendsInNeed
{
    class FriendsInNeed
    {
        static int minDistance = int.MaxValue;
        static int hospitalDistance = 0;
        static Dictionary<int, Node> Nodes = new Dictionary<int, Node>();
        static HashSet<int> hospitals = new HashSet<int>();
        static void Main(string[] args)
        {
            ReadInput();
            int shortestDistance = CalculateDistances();
            Console.WriteLine(shortestDistance);
        }

        private static int CalculateDistances()
        {
            foreach (int hospital in hospitals)
            {
                foreach (var node in Nodes) //djikstra's
                {
                    node.Value.currentDistance = int.MaxValue;
                }
                HashSet<Node> usedNodes = new HashSet<Node>();
                DFS(Nodes[hospital], 0, usedNodes);
                usedNodes.Clear();
                //int hospitalDistance = 0;
                //Console.Write("{0} -> ", hospital);
                foreach (var node in Nodes)
                {
                    if (!node.Value.isHospital)
                    {
                        // Console.Write("{0}({1}) -> ", node.Value.Name, node.Value.currentDistance);
                        hospitalDistance += node.Value.currentDistance;
                    }
                }
                //Console.WriteLine();
                if (hospitalDistance < minDistance)
                {
                    minDistance = hospitalDistance;
                }
            }
            return minDistance;
        }

        private static void ReadInput()
        {
            int[] inputLine = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(m => int.Parse(m)).ToArray();
            int[] hosp = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(m => int.Parse(m)).ToArray();
            foreach (int hospital in hosp)
            {
                hospitals.Add(hospital);
            }

            for (int i = 0; i < inputLine[1]; i++)
            {
                int[] street = Console.ReadLine().Split().Select(m => int.Parse(m)).ToArray();
                Node parent, child;
                if (!Nodes.ContainsKey(street[0]))
                {
                    parent = new Node(street[0]);
                    if (hospitals.Contains(street[0]))
                    {
                        parent.isHospital = true;
                    }
                    Nodes.Add(street[0], parent);
                }
                else
                {
                    parent = Nodes[street[0]];
                }
                if (!Nodes.ContainsKey(street[1]))
                {
                    child = new Node(street[1]);
                    if (hospitals.Contains(street[1]))
                    {
                        child.isHospital = true;
                    }
                    Nodes.Add(street[1], child);
                }
                else
                {
                    child = Nodes[street[1]];
                }
                parent.AddChild(child, street[2]);
                child.AddChild(parent, street[2]);
            }
        }
        private static void DFS(Node node, int sum, HashSet<Node> usedNodes)
        {
            if (sum < node.currentDistance)
            {
                //if (!node.isHospital)
                //{
                //    hospitalDistance += node.currentDistance == int.MaxValue ? sum : sum - node.currentDistance;
                //}
                node.currentDistance = sum;
            }
            usedNodes.Add(node);
            HashSet<Node> nodesUsedByChildren = new HashSet<Node>();
            foreach (var child in node.Children)
            {
                if (!usedNodes.Contains(child.Key))
                {
                    DFS(child.Key, sum + child.Value, usedNodes);
                        nodesUsedByChildren.Add(child.Key);
                }
            }
            foreach (Node child in nodesUsedByChildren)
            {
                usedNodes.Remove(child);
            }
            usedNodes.Clear();
        }
    }

    class Node
    {
        public int Name { get; set; }
        public Dictionary<Node, int> Children;
        public bool isHospital;
        public int currentDistance = int.MaxValue;
        public Node(int Name)
        {
            this.Name = Name;
            this.Children = new Dictionary<Node, int>();
            this.isHospital = false;
        }
        public void AddChild(Node Child, int Distance)
        {
            if (!this.Children.ContainsKey(Child))
            {
                this.Children.Add(Child, Distance);
            }
        }
    }
}